package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WemediaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wemedia/api/v1")
public class WemediaUserController implements WmUserControllerApi {
    @Autowired
    private WemediaService wemediaService;

    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable String  name) {
        if(name!=null&& StringUtils.isEmpty(name)){
            WmUser wmUser = wemediaService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
            return wmUser;
        }
        return null;
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {
        wemediaService.save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
